<?php

use Faker\Factory as Faker;
use App\Models\ChannelVisitUser;
use App\Repositories\ChannelVisitUserRepository;

trait MakeChannelVisitUserTrait
{
    /**
     * Create fake instance of ChannelVisitUser and save it in database
     *
     * @param array $channelVisitUserFields
     * @return ChannelVisitUser
     */
    public function makeChannelVisitUser($channelVisitUserFields = [])
    {
        /** @var ChannelVisitUserRepository $channelVisitUserRepo */
        $channelVisitUserRepo = App::make(ChannelVisitUserRepository::class);
        $theme = $this->fakeChannelVisitUserData($channelVisitUserFields);
        return $channelVisitUserRepo->create($theme);
    }

    /**
     * Get fake instance of ChannelVisitUser
     *
     * @param array $channelVisitUserFields
     * @return ChannelVisitUser
     */
    public function fakeChannelVisitUser($channelVisitUserFields = [])
    {
        return new ChannelVisitUser($this->fakeChannelVisitUserData($channelVisitUserFields));
    }

    /**
     * Get fake data of ChannelVisitUser
     *
     * @param array $postFields
     * @return array
     */
    public function fakeChannelVisitUserData($channelVisitUserFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'channel_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'visit_num' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $channelVisitUserFields);
    }
}
